package com.syl.auth.utils;

import com.syl.auth.model.LocalUser;

/**
 * @ClassName ThreadLocalUserUtil
 * @Description ThreadLocalUserUtil
 * @Author YunLong
 * @Date 2023/4/27 22:38
 */
public class ThreadLocalUserUtil {
    private static ThreadLocal<LocalUser> LOCAL_USER = new ThreadLocal<>();

    public static Long getLocalOrgId() {
        return getLocalUser().getOrgId();
    }

    public static Long getLocalUserId() {
        return getLocalUser().getUserId();
    }

    private static LocalUser getLocalUser() {
        return LOCAL_USER.get();
    }

    public static LocalUser getAndRemove() {
        LocalUser user = LOCAL_USER.get();
        removeLocalUser();
        return user;
    }

    private static void removeLocalUser() {
        LOCAL_USER.remove();
    }

    public static void setLocalUser(LocalUser user) {
        LOCAL_USER.set(user);
    }
}
